package com.happy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.happy.dao.PaperMapper;
import com.happy.entity.PaperEntity;
import com.happy.service.IPaperService;
import com.happy.util.StateEnum;
import com.happy.util.StateException;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @Author: Wuzh
 * @Description:
 * @Date Created in 20:32 2021/1/26
 * @return
 */
@Service
public class PaperServiceImpl extends ServiceImpl<PaperMapper, PaperEntity> implements IPaperService {

    @Resource
    private PaperMapper paperMapper;

    @Override
    public List<PaperEntity> queryList (PaperEntity paperEntity) {
//        QueryWrapper<PaperEntity> queryWrapper = new QueryWrapper<> ();
        if ( paperEntity == null ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        if ( paperEntity == null ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        List<PaperEntity> paperEntities = paperMapper.queryList ( paperEntity );
        return paperEntities;
    }

    @Override
    public PaperEntity querySingle (int id) {
        if ( id == 0 ) {
            throw new StateException ( StateEnum.PRIMARY_NULL_EXCE );
        }
        PaperEntity paperEntity = baseMapper.selectById ( id );
        return paperEntity;
    }

    @Override
    public PaperEntity addSingle (PaperEntity paperEntity) {
        if ( paperEntity == null ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        paperEntity.setCreateTime ( new Date () );
        int insert = baseMapper.insert ( paperEntity );
        if ( insert == 0 ) {
            throw new StateException ( StateEnum.INSERT_EXCE );
        }
        return paperEntity;
    }
}
